<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/views1/DTD/views1-transitional.dtd">
<f:view xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	xmlns:util="http://java.sun.com/jsf/composite/util">
	<ui:composition template="/views/layout/main.xhtml">
		<ui:define name="conteudo">
			<h:form id="formPrincipal">
				<div class="grid_18">
					<div class="grid_18">
						<p:spacer height="10px;"/>
					</div>
					<div class="grid_18">
						<c:if test="#{questaoBean.questaoEmEdicao}">
							<p:commandButton ajax="true" update="formPrincipal" action="#{questaoBean.desistirCreate}" value="Desistir"/>
							<p:commandButton ajax="true" update="formPrincipal" action="#{questaoBean.salvar}" value="Salvar"/>
						</c:if>
						<c:if test="#{!questaoBean.questaoEmEdicao}">
							<p:commandButton immediate="true" value="Novo" ajax="true" update="formPrincipal" action="#{questaoBean.create}"/>
							<p:commandButton rendered="#{questaoBean.questaoBaseInstance.id != null}" immediate="true" value="Editar" ajax="true" update="formPrincipal" action="#{questaoBean.edit}"/>
							<p:commandButton immediate="true" value="Buscar" ajax="true" update="formBuscaQuestao" action="#{questaoBean.prepararBuscaQuestao}" oncomplete="promptBuscaQuestao.show();"/>
							<p:commandButton rendered="#{questaoBean.questaoBaseInstance.id != null}" type="button" value="Excluir" onclick="promptDeleteQuestao.show();"/>
							<p:commandButton action="goHome" value="Home" style="float: right;"/>
						</c:if>
					</div>
					<div class="grid_18 titulo">
						<h:outputText value="Visualizar Questão"/>
					</div>
					<div class="grid_18">
						<p:messages redisplay="false" id="mensagemMain"/>
					</div>
					<div class="grid_4">
						<h:outputText value="Código"/>
					</div>
					<div class="grid_6">
						<p:inputText disabled="#{!questaoBean.questaoEmEdicao}" style="width: 185px;" value="#{questaoBean.questaoBaseInstance.codigo}"/>
					</div>
					<div class="grid_2">
						<h:outputText value="Dificuldade"/>
					</div>
					<div class="grid_6">
						<h:selectOneMenu disabled="#{!questaoBean.questaoEmEdicao}" style="width: 235px;" 
						styleClass="ui-inputfield ui-widget ui-state-default ui-corner-all" 
						value="#{questaoBean.questaoBaseInstance.grauDificuldade}">
							<f:selectItem itemLabel="Selecione..." itemValue="#{null}"/>
							<f:selectItems value="#{enumBean.tipoGrauDificuldade}"
							var="var" itemLabel="#{var}" itemValue="#{var}"/>
						</h:selectOneMenu>
					</div>
					<div class="grid_18">
						<p:spacer height="10px;"/>
					</div>
					<div class="grid_4">
						<h:outputText value="Cadastrada Por"/>
					</div>
					<div class="grid_6">
						<p:inputText disabled="true" style="width: 185px;" value="#{questaoBean.questaoBaseInstance.professor.nomeCompleto}"/>
					</div>
					<div class="grid_2">
						<h:outputText value="Assunto"/>
					</div>
					<div class="grid_6">
						<p:inputText disabled="#{!questaoBean.questaoEmEdicao}" id="palavraChave" style="width: 225px;" value="#{questaoBean.questaoBaseInstance.palavraChave.nome}"/>
					</div>
					<div class="grid_18">
						<p:spacer height="10px;"/>
					</div>
					<div class="grid_4">
						<h:outputText value="Cabeçalho"/>
					</div>
					<div class="grid_14">
						<p:editor disabled="#{!questaoBean.questaoEmEdicao}" width="550" value="#{questaoBean.questaoBaseInstance.cabecalho}"/>
					</div>
					<div class="grid_18">
						<p:spacer height="10px;"/>
					</div>
					<div class="grid_18">
						<div style="top: 15px;float: left; width: 400px;">
							<h1>Alternativas</h1>
						</div>
						<div style="float: left;width: 300px;">
						<h:panelGroup id="painelSlave">
							<c:if test="#{questaoBean.questaoEmEdicao}">
								<p:commandButton rendered="#{questaoBean.alternativaBaseInstance.texto != null}" ajax="true" update="formPrincipal:mensagemMain, formPrincipal:dataTableAlternativaShow" onclick="promptDeleteAlternativa.show();" value="Excluir" style="float: right;"/>
								<p:commandButton rendered="#{questaoBean.alternativaBaseInstance.texto != null}" ajax="true" update="formEditAlternativa" action="#{questaoBean.prepararEditarAlternativa}" oncomplete="promptEditAlternativa.show();" value="Editar" style="float: right;"/>
								<p:commandButton ajax="true" update="formCreateAlternativa" action="#{questaoBean.prepararIncluirAlternativa}" oncomplete="promptCreateAlternativa.show();" value="Nova" style="float: right;"/>
								<p:commandButton rendered="#{questaoBean.alternativaBaseInstance.texto != null}" ajax="true" update="formPrincipal:dataTableAlternativaShow, formPrincipal:mensagemMain" action="#{questaoBean.marcarAlternativaCorreta}" value="Marcar Correta" style="float: right;"/>
							</c:if>
							<c:if test="#{!questaoBean.questaoEmEdicao}">
								<p:commandButton ajax="true" rendered="#{questaoBean.alternativaBaseInstance.id != null}" update="formDetailAlternativa" action="#{questaoBean.prepararEditarAlternativa}" oncomplete="promptDetailAlternativa.show();" value="Detalhar" style="float: right;"/>
							</c:if>
						</h:panelGroup>
						</div>
					</div>
					<div class="grid_18">
						<p:spacer height="10px;"/>
					</div>
					<div class="grid_18">
						<p:dataTable id="dataTableAlternativaShow"
									emptyMessage="Nenhum registro encontrado"
									paginator="true"
									selection="#{questaoBean.alternativaBaseInstance}"
									selectionMode="single"
									update="formPrincipal:painelSlave"
									rowUnselectListener="#{questaoBean.alternativaUnSelect}"
									onRowUnselectUpdate="formPrincipal:painelSlave"
									rows="10" paginatorPosition="top"
									value="#{questaoBean.alternativaBaseList}"
									var="model">
							<p:column style="width: 600px;" headerText="Texto">
								<h:outputText value="#{model.texto}"/>
							</p:column>
							<p:column headerText="Correta?">
								<h:outputText rendered="#{model == questaoBean.alternativaCorretaInstance}" value="Sim"/>
							</p:column>
						</p:dataTable>
					</div>
				</div>
			</h:form>
			<ui:include src="/views/questoes/_prompt.xhtml"/>
			<ui:include src="/views/questoes/_delete.xhtml"/>
			<ui:include src="/views/questoes/alternativa/_create.xhtml"/>
			<ui:include src="/views/questoes/alternativa/_edit.xhtml"/>
			<ui:include src="/views/questoes/alternativa/_detail.xhtml"/>
			<ui:include src="/views/questoes/alternativa/_delete.xhtml"/>
		</ui:define>
	</ui:composition>
</f:view>